import scipy.io as sio
import  numpy as np
from  biosppy import  storage
from biosppy.signals import emg
import  biosppy.signals as bios
import matplotlib.pyplot as plt

#对数据进行降噪处理......！
data = sio.loadmat('ugodata.mat')
semg_signals = data['emg']
semg_signals = semg_signals.T

filtered_signals=[]
for i in range(10):
    filtered_signal=bios.tools.filter_signal(semg_signals[i-1],'butter','bandpass',3,[10,499])
    filtered_signals.append(filtered_signal[0])
print(filtered_signals)
#plt.figure(figsize=(15, 10))
#plt.plot(filtered_signals[2])
#plt.show()


integrated_data = {}
#labled_data1=[]
#for ReturnTuple in filtered_signals:
#    labled_data1.append(filtered_signals[0])
array1 = np.array(filtered_signals)
#array1 = np.squeeze(array1, axis=0)
array1 = np.transpose(filtered_signals)
integrated_data["emg"]=array1

for label in data.keys():
    if isinstance(data["label"], np.ndarray):
       integrated_data["label"] = data["label"]

print('integrated_data:')
print(integrated_data)
sio.savemat('ugodataprocess.mat',integrated_data)